package com.github.cosycode.imgtool.tool;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <b>Description : </b>
 * <p>
 * <b>created in </b> 2022/8/7
 * </p>
 *
 * @author pengfchen
 * @since 1.0
 **/
public class RepeatRecordMap<K, V> extends HashMap<K, V> {

    private Map<K, List<V>> repeatMap;

    @Override
    public V put(K key, V value) {
        V uniqueVal = super.get(key);
        if (uniqueVal == null) {
            super.put(key, value);
        } else {
            List<V> list = repeatMap.computeIfAbsent(key, k -> new ArrayList<V>());
            list.add(value);
        }
        return value;
    }

}
